#ifndef __M0601C_H
#define __M0601C_H

#include "M0601C_driver.h"
#include <QTimer>

#define MOTOR_MODE_CURRENT  0x01
#define MOTOR_MODE_VELOCITY 0x02
#define MOTOR_MODE_POSITION 0x03

class M0601C : public QObject
{
    Q_OBJECT
public:
    explicit M0601C(int motorId, MotorDriver *driver, QObject *parent = nullptr);
    ~M0601C();

    // 获取参数
    double getPosition() const;
    double getVelocity() const;
    double getCurrent() const;

    // 设置参数
    void setTargetPosition(double targetPosition);
    void setTargetVelocity(double targetVelocity, double acceleration_time = 0.1, bool brake = false);
    void setTargetCurrent(double targetCurrent);
signals:
    void updated(); // 参数更新信号

private slots:
    void updateStatus(const QByteArray &response); // 响应处理
    void refreshStatus();                         // 定时刷新状态

private:
    uint8_t id;
    MotorDriver *driver; // 驱动层对象
    double position;
    double velocity;
    double current;
    uint8_t crc8_maxim(const uint8_t *data, uint8_t length);


    QTimer *refreshTimer; // 定时刷新器
};


#endif
